package cn.gs.controller.filterTest;

import com.sun.net.httpserver.HttpsServer;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@RestController
public class TestController extends HttpServlet {

    @GetMapping("/test")
    public String test( @RequestParam String p1, @RequestParam String p2, @RequestParam String p3,@RequestParam String p4){
        System.out.println("TestController类test()方法");
        System.out.println(p1.toString());
        System.out.println(p2.toString());
        System.out.println(p3.toString());
        System.out.println(p4.toString());
        return "test_ok";
    }

    @GetMapping("/doGet")
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
        out.println("<HTML>");
        out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");
        out.println("  <BODY>");
        System.out.println(request.getParameter("p1").toString());
        System.out.println(request.getParameter("p2").toString());
        System.out.println(request.getParameter("p3").toString());
        System.out.println(request.getParameter("p4").toString());
        System.out.println(request.getParameter("paramName").toString());
        System.out.println(response.getStatus());

        out.println(request.getParameter("p1") + "<br>");
        out.println(request.getParameter("p2") + "<br>");
        out.println(request.getParameter("p3") + "<br>");
        out.println(request.getParameter("p4") + "<br>");
        out.println(request.getParameter("paramName") + "<br>");
        out.println(response.getStatus()   + "<br>");
        out.println("  </BODY>");
        out.println("</HTML>");
        out.flush();
        out.close();
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        this.doGet(request, response);
    }

}
